package com.sjyl.kaoshitong.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.sjyl.kaoshitong.R;
import com.sjyl.kaoshitong.adapter.MyDocumentRecyclerViewAdapter;
import com.sjyl.kaoshitong.util.Cheeses;

import java.util.List;

/**
 * Created by ChangerLow on 15/4/25.
 * Email: changerlow@qq.com
 */
public class MyDocumentFragment extends Fragment{
    private static final String TAG = "MyDocumentFragment";
    private SwipeRefreshLayout swipeRefreshLayout;
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyDocumentRecyclerViewAdapter recyclerViewAdapter;
    private List<String> data =null;



    public static MyDocumentFragment newInstance(String param){
        MyDocumentFragment fragment = new MyDocumentFragment();
        Bundle bundle = new Bundle();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_my_document_layout, container, false);
        swipeRefreshLayout = (SwipeRefreshLayout)rootView.findViewById(R.id.swipe_refresh_layout);
        swipeRefreshLayout.setColorSchemeResources(R.color.color_primary, R.color.color_primary_dark);
        recyclerView = (RecyclerView)rootView.findViewById(R.id.recyclerview);
        data = Cheeses.randomList(20);
        layoutManager = new LinearLayoutManager(getActivity());
        recyclerViewAdapter = new MyDocumentRecyclerViewAdapter(data);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(recyclerViewAdapter);
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                List<String> addOnData = Cheeses.randomList(5);
                data.addAll(addOnData);
                recyclerViewAdapter.notifyDataSetChanged();
                swipeRefreshLayout.setRefreshing(false);
            }
        });
        return rootView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }


}
